package com.magicalcoder.youyamvc.web.controller.web.sse;

import com.magicalcoder.youyamvc.web.common.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.concurrent.TimeUnit;

/**
 * Created by hzhedongyu on 2016/12/28.
 */
@Controller
@RequestMapping(value = "/web/sse/")
public class SSEController  extends BaseController{

    @RequestMapping(value = "index")
    public String page(){
        return "web/sse/index.vm";
    }

    @RequestMapping(value="tell_me_what_happen",produces = "text/event-stream;charset=utf-8")
    public @ResponseBody String push(){
        try {
            TimeUnit.SECONDS.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return "data:系统有更新"+System.currentTimeMillis()+"\n\n";
    }

}
